package com.aaa.service.impl;

import com.aaa.dao.UserDao;
import com.aaa.dto.AdminDto;
import com.aaa.dto.AdminRoleDto;
import com.aaa.dto.UserDto;
import com.aaa.pojo.DefaultMsg;
import com.aaa.pojo.User;
import com.aaa.service.UserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 用户管理实体类
 */
@Service
@Transactional
public class UserServiceImpl extends ServiceImpl<UserDao, User> implements UserService {

    @Autowired
    private UserDao userDao;

    @Override
    public List<UserDto> findAllUser() {
        return userDao.findAllUser();
    }

    @Override
    public List<AdminDto> findAllAdminUser() {
        return userDao.findAllAdminUser();
    }

    @Override
    public List<AdminRoleDto> findAdminRoleList() {
        return userDao.findAdminRoleList();
    }

    @Override
    public DefaultMsg updateRoleByAdminId(Integer userId, Integer roleId) {
        DefaultMsg defaultMsg = new DefaultMsg(200, 1, null, null);
        int i = userDao.updateRoleByAdminId(userId, roleId);
        if (i == 0) defaultMsg.setMsg(0);
        return defaultMsg;
    }
}
